<!DOCTYPE html>
<html>

<head>
    <title>编辑游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/editTravels.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script src="/js/My97DatePicker/WdatePicker.js"></script>
    <script src="/js/plugins/eleditor/Eleditor.min.js"></script>
    <script src="/js/plugins/eleditor/webuploader.min.js"></script>
    <script src="/js/common.js"></script>


    <script>
        $(function () {
            var Edr = new Eleditor({
                el: '#contentEditor',
                upload:{
                    server: '/images'
                }
            });


            $("#demo").click(function () {
                var ret= Edr.getContent();
            })

            $("#changeBtn").click(function () {
                $("#fileInp").click();
            })

            $("#fileInp").change(function () {
                if ($(this).val()) {
                    $("#fileForm").ajaxSubmit(function (data) {
                        if (data.status) {
                            $("#coverUrl").prop("src",data.url)
                        }
                    })
                }
            })
           /* <option value="1">广州</option>*/

            $.get("/regions",function (data) {
                var option="";
                $.each(data,function (index,value) {
                    option+='<option value="'+value.id+'">'+value.name+'</option>';
                })
                $("#detailForm select[name='place.id']").html(option)

                var param = getParams();
                if (param.id) {
                    $.get("/travels/"+param.id,function (data) {
                        $(".travels").renderValues(data);

                        if (data.id) {
                            $("#detailForm").prop("action","/travels/"+param.id)
                            $("#detailForm input[name='_method']").val("put");
                        }
                    })
                }



            })

            $("#detailForm input[name='travelTime']").click(function () {
                    WdatePicker({
                        readOnly:true,
                        maxDate:new Date()
                    });
            })

            function save() {
                $("#detailForm input[name='title']").val($("#title").val());
                $("#detailForm input[name='coverUrl']").val($("#coverUrl").prop("src"));
                $("#detailForm input[name='travelContent.content']").val(Edr.getContent());
            }

                $("#detailForm").ajaxForm(function (data) {
                    if (data.success) {
                        $(document).dialog({
                            autoClose: 1000,
                            content: '保存成功',
                        });
                        location.href="/mine/travels.html";
                    }else {
                        $(document).dialog({
                            overlayClose: true,
                            content: '保存失败,稍后再试',
                        });
                    }
                })




            $("#save").click(function () {
                save();
                $("#detailForm input[name='state']").val(0);
                $("#detailForm").submit();

            })

            $("#release").click(function () {
                save();
                $("#detailForm input[name='state']").val(1);
                $("#detailForm").submit();
            })


        })


    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:window.history.go(-1);">
                <span><i class="fa fa-times"></i></span>
            </a>
        </div>
        <div class="col-5"></div>
        <div class="col" style="text-align: right;">
            <i class="fa fa-floppy-o fg-fw" id="save"><span>保存</span></i>
            <i class="fa fa-check" id="release"><span>发布</span></i>
        </div>
    </div>
</div>

<div class="travels form-group">
    <div class="cover">
        <img id="coverUrl" width="100%" render-src="coverUrl" height="200px" />
       
            <button type="button" class="btn" id="changeBtn">
                <i class="fa fa-pencil-square-o"></i>
                <small>更换封面</small>
            </button>
       <form id="fileForm" method="post" action="/images" enctype="multipart/form-data"/>
           <input type="file" name="file" style="display: none" id="fileInp" accept="image/*">
       </form>

    </div>
    <div class="title">
        <input class="form-control" id="title" render-value="title"  placeholder="请输入标题"/>
    </div>
    <h6 href="#">点击文章内容即可编辑</h6>
    <div id="contentEditor" render-html="travelContent.content">

    </div>
    <hr/>
    <div class="container">
        <form id="detailForm" method="post" action="/travels">
            <input type="hidden" name="title">
            <input type="hidden" name="coverUrl">
            <input type="hidden" name="state">
            <input type="hidden" name="travelContent.content">
            <input type="hidden" name="_method" >
            <label>出行时间:</label>
            <input type="text" name="travelTime" render-value="travelTime"  class="form-control" >
            <label>出行天数:</label>
            <input type="number" name="days" render-value="days" class="form-control">
            <label>参与人物:</label>
            <select class="c-select form-control" name="person" render-value="person" >
                <option value="1" selected>一个人的旅行</option>
                <option value="2">和父母</option>
                <option value="3">和朋友</option>
                <option value="4">和同事</option>
                <option value="5">和爱人</option>
                <option value="6">和其他</option>
            </select>
            <label>人均费用:</label>
            <input type="text" name="perExpends" render-value="perExpends" class="form-control">

            <label>旅游地点:</label>
            <select class="form-control"  name="place.id" render-value="place.id" >
            </select>


            <div class="form-check">
                <label class="form-check-label">
                    <input class="form-check-input" type="checkbox"  name="isPublic" render-attr="checked=isPublic">是否公开
                </label>
            </div>

        </form>
    </div>

    <hr/>

</div>


</body>

</html>